/*
 * Author: Alberto De Pena
 * Applied Algorithms
 * sched.cpp
 */
#include <iostream>
#include <fstream>
#include <queue>
using namespace std;

struct Job
{
    int profit, weeks, order;

    bool operator<( const Job& job ) const
    {
        if( weeks < job.weeks )
            return true;
        else if( weeks == job.weeks )
        {
            if( profit < job.profit )
                return true;
            else if( profit == job.profit )
            {
                if( order < job.order )
                    return true;
            }
        }
        return false;
    }
};

void newProfit( int profits[], int oldProfit, int position )
{
    bool done = false;
    for( int i = 0; !done && position - i > 0; i++ )
    {
        if( oldProfit > profits[position - i] )
            {
                if( profits[position - i] > 0 )
                    newProfit( profits, profits[position-i], position-i );
                
                profits[position - i] = oldProfit;
                done = true;
            }
    }
}

void main()
{
    ifstream fin;
    ofstream fout;
    priority_queue<Job> Jobs;
    int orders, i, SUM, MaxDeadLine, profits[1001];
    Job job;
    profits[0] = 0;

    fin.open( "sched.in" );
    fout.open( "sched.out" );

    fin >> orders;
    while( orders != 0 )
    {
        SUM = 0;
        MaxDeadLine = 0;
        for( i = 0; i < orders; i++ )
        {
            fin >> job.order >> job.weeks >> job.profit;
            if( job.weeks > MaxDeadLine )
                MaxDeadLine = job.weeks;
            Jobs.push( job );
        }

        for( i = 1; i <= MaxDeadLine; i++ )
            profits[i] = 0;

        while( !Jobs.empty() )
        {
            job = Jobs.top();
            bool done = false;
            for( i = 0; !done && MaxDeadLine - i > 0; i++ )
            {
                if( job.profit > profits[MaxDeadLine - i] && job.weeks >= MaxDeadLine - i )
                {
                    if( profits[MaxDeadLine - i] > 0 )
                        newProfit( profits, profits[MaxDeadLine-i], MaxDeadLine-i );
                    
                    profits[MaxDeadLine - i] = job.profit;
                    done = true;
                }
            }
            Jobs.pop();
        }

        for( i = 1; i <= MaxDeadLine; i++ )
            SUM += profits[i];

        fout << SUM << endl;
        fin >> orders;
    }

    fin.close();
    fout.close();
}

